<?php
class PitchSubscription extends AppModel {
	var $name = 'PitchSubscription';
	var $validate = array(
		'user_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
		'pitch_id' => array(
			'numeric' => array(
				'rule' => array('numeric'),
				//'message' => 'Your custom message here',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);
	//The Associations below have been created with all possible keys, those that are not needed can be removed

	var $belongsTo = array(
		'User' => array(
			'className' => 'User',
			'foreignKey' => 'user_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		),
		'Pitch' => array(
			'className' => 'Pitch',
			'foreignKey' => 'pitch_id',
			'conditions' => '',
			'fields' => '',
			'order' => ''
		)
	);
	
	function find_subscribed($user_id = null, $param = false) {
		if ($user_id == null)
			return false;
		if ($param == false)
			$data = $this->find('all', array('conditions' => array('PitchSubscription.user_id' => $user_id)));
		else
			$data = $this->find('all', array('conditions' => array('PitchSubscription.user_id' => $user_id, 'Pitch.deadline >' => date('Y-m-d'))));
		return $data;
	}
		
}
?>
